﻿using UnityEngine;
using System.Collections;

public class GameController : MonoBehaviour {
    public GameObject hazard;
    public Vector3 spawnValues;
    private Vector3 spawnPosition = Vector3.zero;
    private Quaternion spawnRotation;
    public int hazardCount = 100;
    public int score = 0;
    public Rect scorePosition;
    public Rect OverPosition;
    public GUIStyle style;
    public bool isAlive;
    void Awake()
    {
        isAlive = true;
    }
    IEnumerator SpawnWaves()
    {
        yield return new WaitForSeconds(1.0f);
    
            for (int i = 0; i < hazardCount; i++)
            {
                spawnPosition.x = Random.Range(-spawnValues.x, spawnValues.x);
                spawnPosition.z = spawnValues.z;
                spawnRotation = Quaternion.identity;
                Instantiate(hazard, spawnPosition, spawnRotation);
                yield return new WaitForSeconds(0.5f);
        }
           
    }
    // Use this for initialization
	void Start () {
        StartCoroutine(SpawnWaves());
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetKeyDown(KeyCode.R))
        {
            Application.LoadLevel(Application.loadedLevel);
        }
	}
    void OnGUI()
    {
        GUI.Label(scorePosition, "得分：" + score, style);
        if (isAlive == false)
        {
            
            GUI.Label(OverPosition, "Game Over", style);
        }
    }
}
